package org.nf.web.servlet;

import cn.hutool.core.util.ReflectUtil;
import org.nf.web.servlet.annotation.Interceptor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangl
 * @date 2024/5/23
 */
public class HandlerInterceptorRegistration {

    private final List<HandlerInterceptor> interceptorList = new ArrayList<>();

    public void addInterceptors(List<Class<?>> handlerInterceptorClassList) {
        handlerInterceptorClassList.forEach(this::addInterceptor);
    }

    public void addInterceptor(Class<?> handlerInterceptorClass) {
        if(handlerInterceptorClass.isAnnotationPresent(Interceptor.class)) {
            HandlerInterceptor interceptor = (HandlerInterceptor) ReflectUtil.newInstance(handlerInterceptorClass);
            interceptorList.add(interceptor);
        }
    }

    public List<HandlerInterceptor> getInterceptors() {
        return interceptorList;
    }
}